package com.binarysoft.service.operlog;

import java.util.Collection;
import java.util.Date;

import com.binarysoft.service.id.IDService;

import common.framework.dsb.AbstractServiceBean;
import common.framework.dsb.annotation.DSBService;
import common.framework.dsb.service.ServiceContext;

@DSBService(name = "DSB/OperLogService")
public class OperLogServiceBean extends AbstractServiceBean implements OperLogService {

	private OperLogDAO operLogDAO = null;

	@Override
	public void start(ServiceContext serviceContext) throws Exception {
		super.start(serviceContext);
		operLogDAO = new OperLogMysqlDAO();
	}

	@Override
	public void refresh() throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void close() throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public Collection<OperLog> queryOperLog(long fromTime, long endTime) throws Exception {
		return operLogDAO.queryOperLog(fromTime, endTime);
	}

	@Override
	public Collection<OperLog> queryOperLog(long fromTime, long endTime, String userID) throws Exception {
		return operLogDAO.queryOperLog(fromTime, endTime, userID);
	}

	@Override
	public void log(OperLog operLog) throws Exception {
		IDService idService = this.serviceContext.lookup("DSB/IDService");
		operLog.setLogid(idService.nextID());
		operLog.setOperTime(new Date());
		operLogDAO.log(operLog);
	}

	@Override
	public void log(Collection<OperLog> operLogs) throws Exception {
		IDService idService = this.serviceContext.lookup("DSB/IDService");
		for (OperLog operLog : operLogs) {
			operLog.setLogid(idService.nextID());
			operLog.setOperTime(new Date());
		}
		operLogDAO.log(operLogs);
	}

	@Override
	public void deleteLog(long fromTime, long endTime) throws Exception {
		operLogDAO.deleteLog(fromTime, endTime);
	}

	@Override
	public void deleteLog(long fromTime, long endTime, String userID) throws Exception {
		operLogDAO.deleteLog(fromTime, endTime, userID);
	}

}
